<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="tablecloth/tablecloth.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

<?php
//Teamtausch


include("inc/joomlaInt.php");
include("inc/inc_teamtausch.php");
include("inc/inc_configuration.php");

if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{	
	if ($faktiv==1)
	{
		$zeit=time();
		if ($zeit<$fzeit)
		{
			echo "Bitte warte bis ",date("H:i",$fzeit)," Uhr am ",date("d.m.y",$fzeit),".";
			echo "<br><br>
			<center><a href='lima.php' class='button zurueck'>Zurück</a></center>";
			break;
		}
	}
	$te=get_teamtausch_erlaubt($jUser);
		if ($te==1)
		{
			$ligaQ = "SELECT l.name AS name, l.id AS id FROM $tbl_leagues l, $tbl_season s WHERE l.seasonId=s.id AND s.active=1 AND l.type=1";
			$ligaQe = mysql_query($ligaQ);
			
			$i=0;
			
			while ($li = mysql_fetch_object($ligaQe))
			{
				$liga = $li->id;
				$ln = $li->name;
				
				$abfrage = "SELECT 	t.name AS name,
									t.id AS id,
									t.rating AS rating,
									l.id AS leagueId
							FROM 	$tbl_teams t, 
									$tbl_lt lt, 
									$tbl_season s,
									$tbl_leagues l
							WHERE 	t.vergeben=0 AND 
									lt.teamid=t.id AND 
									lt.leagueId=l.id AND 
									s.active=1 AND
									l.id=$liga AND
									l.type=1";
				$ergebnis = mysql_query($abfrage);
				
				$anz=mysql_num_rows($ergebnis);
				
				if ($anz>0)
				{
					if ($i>0)
					{
						echo"<br><br>";
					}
					
					echo "<h1>$ln</h1><table><thead><tr><th colspan='4'></th></tr></thead>";
					while ($row = mysql_fetch_object($ergebnis))
					{
						$rating=$row->rating;
						$id=$row->id;
						$r=$rating*10;
						echo "<tr>";
						echo '	<td class="noborder">	<form action="teamtausch_v.php" method="post">
										<input type="radio" name="team" value="',$id,'">
								</td>';
						echo "<td><a href='team_kader.php?team=$id'><img src='img/logos/",$id,".png' width='35' height='35' alt=''></a></td>";
						echo "<td class='noborder'><a href='spiele_team.php?team=$id&liga=$liga'>",$row->name,"</a></td>";
						echo "<td class='noborder'><img src='img/ratings/",$r,".png' width='125' height='25' alt='",$r,"'></td>";
						echo "</tr>";
					}

					echo "<thead><tr><th colspan='4'></th></tr></thead></table><br><input type='submit' value='Übernehmen' class='button eintragen'></form>";
				}
				
				$i++;
			}
			
			echo "<br><br>
			<center><a href='lima.php' class='button zurueck'>Zurück</a></center>";
		}
		else
		{
			echo "Kein Teamtausch mehr erlaubt";
		}
}
?>

</body>
</html>